package com.zxc.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


//订单确认页需要的数据
public class OrderConfirmVo {
    @Getter@Setter
    private List<MemberAddressVo> address;

    //所有选中的购物项
    @Getter@Setter
    private List<OrderItemVo> items;

    //发票......

    //优惠券信息......
    @Getter@Setter
    private Integer integration;//积分信息

    //TODO 防重复令牌
    private String orderToken;

    @Setter@Getter
    private Map<Long,Boolean> skuStocks;//是否有库存

    public BigDecimal getTotal() {
        BigDecimal bigDecimal = new BigDecimal("0");
        if (items != null){
            for (OrderItemVo orderItemVo : items){
                BigDecimal multiply = orderItemVo.getPrice().multiply(new BigDecimal(orderItemVo.getCount().toString()));
                bigDecimal = bigDecimal.add(multiply);
            }
        }
        return bigDecimal;
    }

    //商品数量
    public Integer getCount() {
        Integer count = 0;
        if (items != null && items.size() > 0) {
            for (OrderItemVo item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    private BigDecimal payPrice;//应付的价格

    public BigDecimal getPayPrice() {
        return getTotal();
    }

    public List<MemberAddressVo> getAddress() {
        return address;
    }

    public void setAddress(List<MemberAddressVo> address) {
        this.address = address;
    }

    public List<OrderItemVo> getItems() {
        return items;
    }

    public void setItems(List<OrderItemVo> items) {
        this.items = items;
    }

    public Integer getIntegration() {
        return integration;
    }

    public void setIntegration(Integer integration) {
        this.integration = integration;
    }


    public String getOrderToken() {
        return orderToken;
    }

    public void setOrderToken(String orderToken) {
        this.orderToken = orderToken;
    }

    public void setPayPrice(BigDecimal payPrice) {
        this.payPrice = payPrice;
    }
}
